<template>
	<view class="page">

		<view class="page-content " v-if="info">
			<view class="p14">
				<image :src="info.picUrl" style="width: 100%;" mode="widthFix"></image>
				<view class="bm pb20 mt16">
					<view class="fz16 u-font-bold c0">{{info.activeName}}</view>
					<view class="fz13 u-f-jsb u-flex mt15" style="color: #0F1011;" v-if="info.activeTime">活动时间：{{info.activeTime}}</view>
					
					<view v-if="info.activeAddr" class="fz13 u-f-jsb u-flex mt8" style="color: #0F1011;" @click="toMap">
						活动地点：{{info.activeAddr}}
						<span class="u-flex fz12 btn-nav">
							<image src="../../../static/image/ic-nav.png" style="width: 28rpx;height: 28rpx;" class="mr4">
							</image>
							导航
						</span>
					</view>
				</view>
				<view class="fz12 c6 u-f-jsb u-flex mt20">状态<span class="c0"
						:class="'status'+info.status">{{statusAttr[info.status]}}</span></view>
				<view class="fz12 c6 mt12 u-f-jsb u-flex">预约人<span class="c0">{{info.userName}}</span></view>
				<view class="fz12 c6 mt12 u-f-jsb u-flex">手机号码<span class="c0">{{info.mobile}}</span></view>
				<view class="fz12 c6 mt12 u-f-jsb u-flex" v-if="info.supplierName">经销商<span class="c0">{{info.supplierName}}</span></view>
				<view class="fz12 c6 mt12 u-f-jsb u-flex" v-if="info.supplierTime">经销商活动时间<span class="c0">{{info.supplierTime}}</span></view>
				<view class="fz12 c6 mt12 u-f-jsb u-flex" v-if="info.appointTimeFormat">参观日期<span class="c0">{{info.appointTimeFormat}}</span></view>
				<view class="fz12 c6 mt12 u-f-jsb u-flex" v-if="info.visitTime">参观时段<span class="c0">{{info.visitTime}}</span></view>
				<view v-if="info.activeType!='经销商活动'" class="brs5 u-flex mt20 p10 c6 lh20 fz12" style="background: #F6F9F9;align-items: flex-start;">
					<image src="../../../static/image/ic-tips.png"
						style="width: 32rpx;min-width: 32rpx;height: 32rpx;margin:6rpx 10rpx 0 0;"></image>
					如未能按预约时间参加活动，请及时取消预约，取消时间最迟为预约时间的前一天。
				</view>

				<view class="mt30" v-if="info.status==1">
					<!-- <view class="btn" @click="toSign">签到</view> -->
					<view class="btn1" @click="isSuccess=false,showResult=true">取消预约</view>
				</view>
			</view>
		</view>


		<u-popup v-model="showResult" mode="center" border-radius="20" :closeable="false">
			<view class="p15 pt30" style="width: 640rpx;margin: 0 auto;">
				<view v-if="isSuccess">
					<image src="../../../static/image/ic-sign.png" class="w52 h52"
						style="display: block;margin: 0 auto;"></image>
					<view class="fz14 u-font-bold lh22 mt20" style="text-align: center;">
						签到成功<br />祝您活动愉快!
					</view>
				</view>
				<view v-else>
					<image src="../../../static/image/ic-tips.png" class="w52 h52"
						style="display: block;margin: 0 auto;"></image>
					<view class="fz14 u-font-bold lh22 mt20" style="text-align: center;">
						确定要取消<br />本次活动预约吗？
					</view>
				</view>
				<view class="mt36">

					<view class="btn-sure fz14" v-if="isSuccess" @click="showResult=false">确定</view>
					<view class="u-flex" v-else>
						<view class="btn-sure mr10 btn-sure1 fz14" @click="showResult=false">取消</view>
						<view class="btn-sure ml10 fz14" @click="toClose">确定</view>
					</view>
				</view>
			</view>
		</u-popup>

	</view>
</template>

<script>
	import {
		getPlatform
	} from '@/config/util.js'
	export default {
		data() {
			return {
				showResult: false,
				isSuccess: false,
				statusAttr: ['', '待签到', '已签到', '已取消'],
				info: {}
			}
		},
		onLoad(e) {
			this.getInfo(e.id)
		},
		onShow() {},
		methods: {
			toMap() {
				let that=this
				if (that.info.activeLocate) {
					let lng = that.info.activeLocate.split(',')[0]
					let lat = that.info.activeLocate.split(',')[1]
					console.log(lng,lat)
					uni.openLocation({
						latitude: Number(lat),
						longitude: Number(lng),
						name:that.info.title,
						address:that.info.activeAddr,
						success: function() {
							console.log('success');
						},
						error: function(err) {
							console.log(err);
						}
					});
				}
			},
			getInfo(id) {

				this.$api.appoint_detail({
					id: id
				}, res => {
					if (res.code==200) {
						this.info = res.data
					}
				})
			},
			toSign() {


				this.$api.appointSign({
					id: this.info.id
				}, res => {
					if (res.code==200) {
						this.getInfo(this.info.id)
						this.showResult=true
						this.isSuccess=true
					} else {
						this.$common.errorToShow(res.message)

					}
				})

			},
			toClose() {


				this.$api.appointCancel({
					id: this.info.id
				}, res => {
					if (res.code==200) {
						this.getInfo(this.info.id)
						this.showResult=false
					} else {
						this.$common.errorToShow(res.message)

					}
				})

			},
		}
	}
</script>

<style lang="scss" scoped>
	.btn-nav {

		width: 120rpx;
		height: 50rpx;
		justify-content: center;
		text-align: center;
		color: #fff;
		background: #ABC7C9;
		border-radius: 40px;
	}
	.btn-sure {

		width: 100%;
		height: 80rpx;
		text-align: center;
		color: #fff;
		margin: 0 auto;
		line-height: 80rpx;
		background: #ABC7C9;
		border-radius: 40px;
	}

	.btn-sure1 {

		border: 1px solid #ABC7C9;
		background: #fff;
		color: #ABC7C9;
	}

	.btn {
		background: #ABC7C9;
		height: 80rpx;
		color: #fff;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 50rpx;
		text-align: center;
	}

	.btn1 {
		border: 1px solid #ABC7C9;
		height: 80rpx;
		color: #ABC7C9;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 50rpx;
		text-align: center;
	}

	.line {
		width: 750rpx;
		height: 4rpx;
		position: relative;
		top: -4rpx;
		background: #F6F9F9;
		border-radius: 0px 0px 0px 0px;
	}

	.status1 {
		color: #E54440;
	}

	.status2 {
		color: #39959B;
	}

	.status3 {
		color: #333;
	}
</style>